package com.example.studyFile.asynchronousOptimization;

public class ValidationExecutor {

    public static void main(String[] args) throws Exception {

        long startTime = System.currentTimeMillis(); // 程序开始时间

        logExecutionTime(() -> checkSystemMain(1), "checkSystemMain");
        logExecutionTime(() -> checkBusinessRankLogApp(1), "checkBusinessRankLogApp");
        logExecutionTime(() -> checkBusinessRankLogVendor(1), "checkBusinessRankLogVendor");
        logExecutionTime(() -> checkBusinessRankLogIpPortManage(1), "checkBusinessRankLogIpPortManage");
        logExecutionTime(() -> checkBusinessRankLogDomain(1), "checkBusinessRankLogDomain");
        logExecutionTime(() -> checkBusinessRankLogWeb(1), "checkBusinessRankLogWeb");
        logExecutionTime(() -> checkBusinessRankLogProduct(1), "checkBusinessRankLogProduct");
        logExecutionTime(() -> checkBusinessRankLogBasis(1), "checkBusinessRankLogBasis");
        logExecutionTime(() -> checkBusinessRankLogSystemBasis(1), "checkBusinessRankLogSystemBasis");

        long endTime = System.currentTimeMillis(); // 程序结束时间
        System.out.println("总执行时间: " + (endTime - startTime) + " 毫秒");
    }

    private static void logExecutionTime(RunnableWithException task, String methodName) {
        long start = System.currentTimeMillis();
        try {
            task.run(); // 执行任务
        } catch (InterruptedException e) {
            System.err.println(methodName + " 执行被中断");
            Thread.currentThread().interrupt(); // 恢复中断状态
        }
        long end = System.currentTimeMillis();
        System.out.println(methodName + " 执行时间: " + (end - start) + " 毫秒");
    }

    // 模拟校验方法
    private static void checkSystemMain(int id) throws InterruptedException {

        Thread.sleep(5000 + (long) (Math.random() * 2000)); // 模拟5-7秒的执行时间
    }

    private static void checkBusinessRankLogBasis(int id) throws InterruptedException {

        Thread.sleep(5000 + (long) (Math.random() * 2000)); // 模拟5-7秒的执行时间
    }

    private static void checkBusinessRankLogSystemBasis(int id) throws InterruptedException {

        Thread.sleep(5000 + (long) (Math.random() * 2000)); // 模拟5-7秒的执行时间
    }


    private static void checkBusinessRankLogVendor(int id) throws InterruptedException {

        Thread.sleep(5000 + (long) (Math.random() * 2000)); // 模拟5-7秒的执行时间
    }


    private static void checkBusinessRankLogIpPortManage(int id) throws InterruptedException {

        Thread.sleep(5000 + (long) (Math.random() * 2000)); // 模拟5-7秒的执行时间
    }


    private static void checkBusinessRankLogDomain(int id) throws InterruptedException {

        Thread.sleep(5000 + (long) (Math.random() * 2000)); // 模拟5-7秒的执行时间
    }

    private static void checkBusinessRankLogWeb(int id) throws InterruptedException {

        Thread.sleep(5000 + (long) (Math.random() * 2000)); // 模拟5-7秒的执行时间
    }

    private static void checkBusinessRankLogProduct(int id) throws InterruptedException {

        Thread.sleep(5000 + (long) (Math.random() * 2000)); // 模拟5-7秒的执行时间
    }

    private static void checkBusinessRankLogApp(int id) throws InterruptedException {

        Thread.sleep(5000 + (long) (Math.random() * 2000)); // 模拟5-7秒的执行时间
    }






}
